package cn.itlaobing.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.itlaobing.web.annotation.RequestAnnocation;
import cn.itlaobing.web.dao.ListDao;
import cn.itlaobing.web.exception.MyeEXception;
import cn.itlaobing.web.model.ListModel;
import cn.itlaobing.web.model.PaginatoinModel;
import cn.itlaobing.web.model.UserModel;
import cn.itlaobing.web.service.ListService;
import cn.itlaobing.web.util.StringUtils;

@WebServlet(value="/listServlet/*")
public class ListServlet extends BaseServlet {
	/** 
	 * update:(查询的方法). <br/>
	 * 
	 * @author yan  
	 * @throws IOException 
	 * @throws ServletException 
	 * @since JDK 1.8 
	 */  
	@RequestAnnocation("/querymore")
	public void queryMore(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		UserModel um=(UserModel)request.getSession().getAttribute("USER");
		ListDao ld=new ListDao();
		Integer userid=um.getId();
		PaginatoinModel<ListModel> paginatoinModel=null;
		try {
			String index = request.getParameter("thisPage");
			if (StringUtils.isBank(index)) {
				index = "1";
			}
			Integer thisPage = Integer.valueOf(index);
			String asize = request.getParameter("size");
			if (StringUtils.isBank(asize)) {
				asize = PaginatoinModel.EVERY_SIZE + "";
			}
			Integer size = Integer.valueOf(asize);
			paginatoinModel = ld.Pagination(thisPage, size, userid);
		}catch (SQLException e) {
			e.printStackTrace();
		}
		request.getSession().setAttribute("LIST",paginatoinModel);
		request.getRequestDispatcher("/WEB-INF/views/userList1.jsp").forward(request, response);
	}
	/** 
	 * delete:(删除的方法). <br/>
	 * 
	 * @author yan 
	 * @param request
	 * @param response 
	 * @since JDK 1.8 
	 */ 
	@RequestAnnocation("/update")
	public void delete(HttpServletRequest request,HttpServletResponse response) throws IOException{
		String listid=request.getParameter("listid");
		String attitude=request.getParameter("attitude");
		ListService ls=new ListService();
		int row=0;
		try {
			row=ls.updateOne(attitude,listid);
			PrintWriter out=response.getWriter();
			out.print(row);
		} catch (MyeEXception myeEXception) {
			myeEXception.printStackTrace();
		}
	}
	/** 
	 * select:(查询的方法). <br/>
	 * 
	 * @author yan 
	 * @param request
	 * @param response 
	 * @since JDK 1.8 
	 */  
	@RequestAnnocation("/select")
	public void select(HttpServletRequest request,HttpServletResponse response) {
		System.out.println("select");	
		
	}
}
